package com.max.back.examination.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.max.back.entity.Check;
import com.max.back.entity.CodeName;
import com.max.back.examination.form.CheckFrom;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CheckDao extends BaseMapper<Check> {

    /**
     * 获取检查列表
     * s1检查表
     * s2患者表、病历表
     * s3检查项表、科室表
     * @return
     */
    @Select(value = "<script> select s1.id,s3.id check_item_id,s2.name username,s2.sex,s3.name check_item_name,\n" +
            "    s3.part,s3.department_name ,s3.execute_status pay_status,s3.check_time,s3.result\n" +
            "    from examination s1 \n" +
            "left join \n" +
            "(select p1.*,p2.id as patient_history_id from patient p1\n" +
            " left join patient_history p2 on p1.id = p2.patient_id) s2\n" +
            " on s1.patient_history_id = s2.patient_history_id\n" +
            " left join \n" +
            " (select a1.*,a2.name department_name from check_item a1\n" +
            " left join department a2 on a1.department_id = a2.id) s3 \n" +
            " on s1.id = s3.check_id" +
            " <if test = \"title !=null and title != ''\" > where s2.name like '%'||#{title}||'%' </if></script>"
    )
    List<CheckFrom> getChecklist(@Param("title") String title);

    /**
     * 录入检查结果
     *
     * @param checkItemId
     * @param result
     */
    @Update(value = "update check_item set result = #{result} , execute_status = '1' where id = #{checkItemId}")
    void edit(@Param("checkItemId") String checkItemId, @Param("result") String result);
}
